package com.tanhua.server.controller;

import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import com.tanhua.server.service.TodayBestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @auther : 白月尘
 * @date : 17:38  2021/10/18
 */
@RestController
@RequestMapping("/tanhua")
public class TanhuaController {
    @Autowired
    private TanhuaService tanhuaService;
    @Autowired
    private TodayBestService todayBestService;

    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto){
        PageResult pageResult=tanhuaService.recommendation(dto);
        return ResponseEntity.ok(pageResult);
    }
    @GetMapping("/todayBest")
    public ResponseEntity<TodayBest> todayBest(){
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(long userId){
        String content=tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(content);
    }
    @GetMapping("/{userId}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("userId") long userId){
        TodayBest vo=tanhuaService.personalInfo(userId);
        return ResponseEntity.ok(vo);
    }
    @PostMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestBody Map map){
        String userId = map.get("userId").toString();
        Long id = Long.valueOf(userId);
        String reply = map.get("reply").toString();
        tanhuaService.reply(id,reply);
        return ResponseEntity.ok(null);
    }
    @GetMapping("/search")
    public ResponseEntity search(String gender,String distance){
        List<NearUserVo> vo=tanhuaService.search(gender,distance);
        return ResponseEntity.ok(vo);
    }
    //探花卡片功能
    @GetMapping("cards")
    public ResponseEntity queryCardsList() {//获取到的卡片集合
        List<TodayBest> list = this.todayBestService.queryCardsList();
        return ResponseEntity.ok(list);
    }
    /**
     * 喜欢
     *
     * @param likeUserId
     * @return
     */
    @GetMapping("{id}/love")
    public ResponseEntity likeUser(@PathVariable("id") Long likeUserId) {
        this.todayBestService.likeUser(likeUserId);//返回的是喜欢的人的用户ID
        return ResponseEntity.ok(null);
    }

    /**
     * 不喜欢
     *
     * @param disLikeUserId
     * @return
     */
    @GetMapping("{id}/unlove")
    public ResponseEntity disLikeUser(@PathVariable("id") Long disLikeUserId) {
        this.todayBestService.disLikeUser(disLikeUserId);
        return ResponseEntity.ok(null);
    }
}
